<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="../../../../header.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
	<style>
		.required-wrap {
			color: #f00;
			margin-left: -6px;
			margin-right: 1px;
			font-size: 12px;
		}
		.wrap {
			margin: 30px 30px 10px 30px;
		}
		.wrap .jobcode {
			margin-top: 20px;
			float: left;
		}
		.wrap-input {
			width: 220px;
			height: 28px;
			margin-left: 40px;
		}
		.wrap-input1 {
			width: 220px;
			height: 28px;
			margin-left: 18px;
		}
		textarea.ui-input {
			height: 60px;
			width: 220px;
		}
	</style>

</head>
<body style="align: center;">
	<div style="margin-top: 30px; margin-left: 30px;">
		<form id="manage-form" action="">
			<div class="wrap">
				<label for="jobcode" style="margin-right: 40px;">部门:</label><input
					type="hidden" name="parentId" id="parentId" /> <span
					id="parentname"></span><div style="float:right;color:red;margin-top:5px">*必须要选择部门</div>
			</div>
			<div class="wrap">
				<label for="jobcode">工号(必填):</label><input type="text"
					class="wrap-input ui-input" name="personcode" id="personcode">
			</div>
			<div class="wrap">
				<label for="jobcode">姓名:</label><input type="text"
					class="wrap-input ui-input" name="personname" id="personname">
			</div>
			<div class="wrap">
				<label for="jobcode">英文民称:</label><input type="text"
					class="wrap-input ui-input" name="personename" id="personename">
			</div>
			<div class="wrap">
				<label for="jobcode">性别:</label> <select id="sexid"
					style="width: 100px; height: 28px; margin-left: 40px;">
					<option value="1000">男</option>
					<option value="1001">女</option>
				</select>
			</div>
			<div class="wrap">
				<label for="jobcode">名族:</label> <select id="nationid"
					style="width: 100px; height: 28px; margin-left: 40px;">
					<option value="1002">汉族</option>
					<option value="1003">非汉族</option>
				</select>
			</div>
			<div class="wrap">
				<label for="jobcode">婚姻:</label> <select id="marriageid"
					style="width: 100px; height: 28px; margin-left: 40px;">
					<option value="1060">未婚</option>
					<option value="1061">已婚</option>
					<option value="1062">脚踏两只船</option>
				</select>
			</div>
			<div class="wrap">
				<label for="jobcode">职位:</label> <select id="postid"
					style="width: 100px; height: 28px; margin-left: 40px;">
					<option value="1065">董事长</option>
					<option value="1066">执行总裁</option>
					<option value="1067">人事经理</option>
					<option value="1068">财务经理</option>
					<option value="1069">内务经理</option>
					<option value="1070">项目经理</option>
					<option value="1071">研发部经理</option>
					<option value="1072">人事经理</option>
					<option value="1073">文员</option>
					<option value="1074">销售经理</option>
					<option value="1075">销售人员</option>
					<option value="1076">采购经理</option>
					<option value="1077">采购文员</option>
				</select>
			</div>
			<div class="wrap">
				<label for="jobcode">身份证号:</label><input type="text"
					class="wrap-input1 ui-input" name="identityno" id="identityno">
			</div>
			<div class="wrap">
				<label for="jobcode">身份证地址:</label><input type="text"
					class="wrap-input1 ui-input" name="homeaddr" id="homeaddr">
			</div>
			<div class="wrap">
				<label for="jobcode">现居住地:</label><input type="text"
					class="wrap-input1 ui-input" name="nowaddr" id="nowaddr">
			</div>
			<div class="wrap">
				<label for="jobcode">出生日期:</label><input type="text"
					class="wrap-input1 ui-input" name="birthdate" id="birthdate">
			</div>
			<div class="wrap">
				<label for="jobcode">毕业日期:</label><input type="text"
					class="wrap-input1 ui-input" name="graduatedate" id="graduatedate">
			</div>
			<div class="wrap">
				<label for="jobcode">入职日期(必填):</label><input type="text"
					class="wrap-input1 ui-input" name="officedate" id="officedate">
			</div>
			<div class="wrap">
				<label for="jobcode">转正日期:</label><input type="text"
					class="wrap-input1 ui-input" name="memberdate" id="memberdate">
			</div>
			<div class="wrap">
				<label for="jobcode">转正标志:</label>
				<div id="ismembered" style="display:inline;">
					<input  class="switch-simple-3" id="switch_ismembered" type="checkbox"><label for="switch_ismembered" class="green"></label>
				</div>
			</div>
			<div class="wrap">
				<label for="jobcode">劳动合同到期日:</label><input type="text"
					class="wrap-input1 ui-input" name="contractdate" id="contractdate">
			</div>
			<div class="wrap">
				<label for="jobcode">劳动合同标志:</label>
				<div id="iscontracted" style="display: inline;">
					<input class="switch-simple-3" id="switch_iscontracted"
						type="checkbox"><label for="switch_iscontracted"
						class="green"></label>
				</div>
			</div>
			<div class="wrap">
				<label for="jobcode">离职时间:</label><input type="text"
					class="wrap-input1 ui-input" name="leavedate" id="leavedate">
			</div>
			<div class="wrap">
				<label for="jobcode">学历:</label> <select id="educationdegree"
					style="width: 100px; height: 28px; margin-left: 40px;">
					<option value="1078">大专</option>
					<option value="1079">本科</option>
					<option value="1080">硕士</option>
					<option value="1081">博士</option>
				</select>
			</div>
			<div class="wrap">
				<label for="jobcode">毕业院校:</label><input type="text"
					class="wrap-input1 ui-input" name="school" id="school">
			</div>
			<div class="wrap">
				<label for="jobcode">专业:</label><input type="text"
					class="wrap-input1 ui-input" name="major" id="major">
			</div>
			<div class="wrap">
				<label for="jobcode">英语:</label> <select id="englishdegreeid"
					style="width: 100px; height: 28px; margin-left: 40px;">
					<option value="1082">大学英语</option>
					<option value="1083">四级</option>
					<option value="1084">六级</option>
					<option value="1085">八级</option>
				</select>
			</div>
			<div class="wrap">
				<label for="jobcode">银行卡号:</label><input type="text"
					class="wrap-input1 ui-input" name="bankCardNo" id="bankCardNo">
			</div>
			<div class="wrap">
				<label for="jobcode">公积金:</label><input type="text"
					class="wrap-input1 ui-input" name="providentFund"
					id="providentFund">
			</div>
			<div class="wrap">
				<label for="jobcode">社保号:</label><input type="text"
					class="wrap-input1 ui-input" name="insuranceno" id="insuranceno">
			</div>
			<div class="wrap">
				<label for="jobcode">金融社保卡号:</label><input type="text"
					class="wrap-input1 ui-input" name="bankinsuranceno" id="bankinsuranceno">
			</div>
			<div class="wrap">
				<label for="jobcode">工卡:</label><input type="text"
					class="wrap-input1 ui-input" name="companycardno"
					id="companycardno">
			</div>
			<div class="wrap">
				<label for="jobcode">港澳通行证:</label><input type="text"
					class="wrap-input1 ui-input" name="hkmcpassport" id="hkmcpassport">
			</div>
			<div class="wrap">
				<label for="jobcode">紧急联系人:</label><input type="text"
					class="wrap-input1 ui-input" name="iceperson" id="iceperson">
			</div>
			<div class="wrap">
				<label for="jobcode">紧急电话:</label><input type="text"
					class="wrap-input1 ui-input" name="icetel" id="icetel">
			</div>
			<div class="wrap">
				<label for="jobcode">邮箱:</label><input type="text"
					class="wrap-input1 ui-input" name="email" id="email">
			</div>
			<div class="wrap">
				<label for="jobcode">手机:</label><input type="text"
					class="wrap-input ui-input" name="mobile" id="mobile">
			</div>
			<div class="wrap">
				<label for="jobcode">微信:</label><input type="text"
					class="wrap-input1 ui-input" name="weixin" id="weixin">
			</div>
			<div class="wrap">
				<label for="jobcode">QQ号:</label><input type="text"
					class="wrap-input1 ui-input" name="qq" id="qq">
			</div>
			<div class="wrap">
				<div class="jobcode">
					<label>备注:</label>
				</div>
				<textarea type="text" id="remark" name="remark"
					class="wrap-input ui-input"></textarea>
			</div>
			<div class="wrap">
				<label for="jobcode">创建时间:</label><input type="text"
					class="wrap-input1 ui-input" name="createtime" id="createtime">
			</div>
			<div class="wrap">
				<label for="jobcode">修改时间:</label><input type="text"
					class="wrap-input1 ui-input" name="updatetime" id="updatetime">
			</div>
			<div class="wrap">
				<label for="jobcode">在职?:</label>
				<div id="active" style="display:inline;">
					<input  class="switch-simple-3" id="switch_active" type="checkbox"><label for="switch_active" class="green"></label>
				</div>
			</div>
		</form>
	</div>

	<script type="text/javascript">
		var api = frameElement.api;
		var operate = api.data.operate;
		var rowid = api.data.rowid;
		var rowdata = api.data.rowdata;
		var companyId = 1;
		var parentname = api.data.parentname;
		var parentId = api.data.parentId;
		var deptname = api.data.deptname;
		var CallBack = api.data.callback;

		$(function() {
			initPopBtns();
			if (operate == "add")
				return false;
			if (operate == "edit") {
				$("#personcode").val(rowdata.personcode);
				$("#personname").val(rowdata.personname);
				$("#personename").val(rowdata.personename);
				if (rowdata.sexid == "女") {
					$("#sexid").val(1001);
				} else if (rowdata.sexid == "男") {
					$("#sexid").val(1000);
				}
				if (rowdata.nationid == "汉族") {
					$("#nationid").val(1002);
				} else if (rowdata.nationid == "非汉族") {
					$("#nationid").val(1003);
				}
				if (rowdata.marriageid == "未婚") {
					$("#marriageid").val(1060);
				} else if (rowdata.marriageid == "已婚") {
					$("#marriageid").val(1061);
				} else if (rowdata.marriageid == "脚踏两只船") {
					$("#marriageid").val(1062);
				}
				if (rowdata.postid == "执行总裁") {
					$("#postid").val(1066);
				} else if (rowdata.postid == "董事长") {
					$("#postid").val(1065);
				} else if (rowdata.postid == "人事经理") {
					$("#postid").val(1067);
				} else if (rowdata.postid == "财务经理") {
					$("#postid").val(1068);
				} else if (rowdata.postid == "内务经理") {
					$("#postid").val(1069);
				} else if (rowdata.postid == "项目经理") {
					$("#postid").val(1070);
				} else if (rowdata.postid == "研发部经理") {
					$("#postid").val(1071);
				} else if (rowdata.postid == "人事助理") {
					$("#postid").val(1072);
				} else if (rowdata.postid == "文员") {
					$("#postid").val(1073);
				} else if (rowdata.postid == "销售经理") {
					$("#postid").val(1074);
				} else if (rowdata.postid == "销售人员") {
					$("#postid").val(1075);
				} else if (rowdata.postid == "采购经理") {
					$("#postid").val(1076);
				} else if (rowdata.postid == "采购文员") {
					$("#postid").val(1077);
				}
				$("#identityno").val(rowdata.identityno);
				$("#homeaddr").val(rowdata.homeaddr);
				$("#nowaddr").val(rowdata.nowaddr);
				$("#birthdate").val(rowdata.birthdate);
				$("#graduatedate").val(rowdata.graduatedate);
				$("#officedate").val(rowdata.officedate);
				$("#memberdate").val(rowdata.memberdate);
				$("#ismembered").html(rowdata.ismembered);
				$("#ismembered input").attr("disabled", false);
				$("#contractdate").val(rowdata.contractdate);
				$("#iscontracted").html(rowdata.iscontracted);
				$("#iscontracted input").attr("disabled", false);
				$("#leavedate").val(rowdata.leavedate);
				if (rowdata.educationdegree == "硕士") {
					$("#educationdegree").val(1078);
				} else if (rowdata.educationdegree == "本科") {
					$("#educationdegree").val(1079);
				}
				$("#school").val(rowdata.school);
				$("#major").val(rowdata.major);
				if (rowdata.englishdegreeid == "英语四级") {
					$("#englishdegreeid").val(1080);
				} else if (rowdata.englishdegreeid == "英语六级") {
					$("#englishdegreeid").val(1081);
				}
				$("#bankCardNo").val(bankCardNo.bankCardNo);
				$("#providentFund").val(rowdata.providentFund);
				$("#insuranceno").val(rowdata.insuranceno);
				$("#bankinsuranceno").val(rowdata.bankinsuranceno);
				$("#companycardno").val(rowdata.companycardno);
				$("#hkmcpassport").val(rowdata.hkmcpassport);
				$("#iceperson").val(rowdata.iceperson);
				$("#icetel").val(rowdata.icetel);
				$("#email").val(rowdata.email);
				$("#mobile").val(rowdata.mobile);
				$("#weixin").val(rowdata.weixin);
				$("#qq").val(rowdata.qq);
				$("#remark").val(rowdata.remark);
				$("#createtime").val(rowdata.createtime);
				$("#updatetime").val(rowdata.updatetime);
				$("#active").html(rowdata.active);
				$("#active input").attr("disabled", false);
				$("#deptid").val(rowdata.deptid);
				$("#parentId").val(parentId);
				$("#parentname").val(parentname);
				$("#deptname").val(deptname);
				categoryTree.selectByValue(rowdata.parentId);
			}
		})

		function initPopBtns() {
			var btnname = "add" == operate ? [ "保存", "关闭" ] : [ "确定", "取消" ];
			api.button(
					{
						id : "confirm",
						name : btnname[0],
						focus : true,
						callback : function(e) {
							var deptid = categoryTree.getValue();
							var parentId = $("#parentId").val();
							var personcode = $("#personcode").val();
							var personname = $("#personname").val();
							var personename = $("#personename").val();
							var sexid = $("#sexid").val();
							var nationid = $("#nationid").val();
							var marriageid = $("#marriageid").val();
							var postid = $("#postid").val();
							var identityno = $("#identityno").val();
							var homeaddr = $("#homeaddr").val();
							var nowaddr = $("#nowaddr").val();
							var birthdate = $("#birthdate").val();
							var graduatedate = $("#graduatedate").val();
							var officedate = $("#officedate").val();
							var memberdate = $("#memberdate").val();
							var ismembered = $("#ismembered input").prop("checked");
							if (ismembered == true) {
								ismembered = 1;
							} else if (ismembered == false) {
								ismembered = 0;
							}
							var contractdate = $("#contractdate").val();
							var iscontracted = $("#iscontracted input").prop(
									"checked");
							if (iscontracted == true) {
								iscontracted = 1;
							} else if (iscontracted == false) {
								iscontracted = 0;
							}
							var leavedate = $("#leavedate").val();
							var educationdegree = $("#educationdegree").val();
							var school = $("#school").val();
							var major = $("#major").val();
							var englishdegreeid = $("#englishdegreeid").val();
							var bankCardNo = $("#bankCardNo").val();
							var providentFund = $("#providentFund").val();
							var insuranceno = $("#insuranceno").val();
							var bankinsuranceno = $("#bankinsuranceno").val();
							var companycardno = $("#companycardno").val();
							var hkmcpassport = $("#hkmcpassport").val();
							var iceperson = $("#iceperson").val();
							var icetel = $("#icetel").val();
							var email = $("#email").val();
							var mobile = $("#mobile").val();
							var weixin = $("#weixin").val();
							var qq = $("#qq").val();
							var remark = $("#remark").val();
							var createtime = $("#createtime").val();
							var updatetime = $("#updatetime").val();
							var active = $("#active input").prop("checked");
							if (active == true) {
								active = 1;
							} else if (active == false) {
								active = 0;
							}

							if (operate == "add") {
							    if(officedate==""){
							    	alert("入职日期不能为空");
							    	return false;
							    }
								
								$.ajax({
									url : 'employee/add',
									type : 'POST',
									dataType : "json",
									data : {
										"companyId" : 1,
										"companyid" : 1,
										"deptid" : deptid,
										"parentId" : parentId,
										"personcode" : personcode,
										"personname" : personname,
										"personename" : personename,
										"sexid" : sexid,
										"nationid" : nationid,
										"marriageid" : marriageid,
										"postid" : postid,
										"identityno" : identityno,
										"homeaddr" : homeaddr,
										"nowaddr" : nowaddr,
										"birthdate" : birthdate,
										"graduatedate" : graduatedate,
										"officedate" : officedate,
										"memberdate" : memberdate,
										"ismembered" : ismembered,
										"contractdate" : contractdate,
										"iscontracted" : iscontracted,
										"leavedate" : leavedate,
										"school" : school,
										"major" : major,
										"englishdegreeid" : englishdegreeid,
										"bankCardNo":bankCardNo,
										"providentFund":providentFund,
										"insuranceno" : insuranceno,
										"bankinsuranceno" : bankinsuranceno,
										"companycardno" : companycardno,
										"hkmcpassport" : hkmcpassport,
										"iceperson" : iceperson,
										"icetel" : icetel,
										"email" : email,
										"mobile" : mobile,
										"weixin" : weixin,
										"qq" : qq,
										"remark" : remark,
										"createtime" : createtime,
										"updatetime" : updatetime,
										"active" : active,

									},
									async : false,
									success : function(data) {
										if (data.status == 200) {
											parent.Public.tips({
												content : "添加员工信息成功"
											})
											CallBack({
												"AddEditDel":"addEditDel"
											});
										} else {
											parent.Public.tips({
												type : 1,
												content : "添加员工信息失败:"
														+ data.msg
											})
										}
									}
								});
							} else {
								$.ajax({
									url : encodeURI("employee/edit"),
									type : "POST",
									data : {
										"id" : rowid,
										"companyId" : 1,
										"companyid" : 1,
										"deptid" : deptid,
										"parentId" : parentId,
										"personcode" : personcode,
										"personname" : personname,
										"personename" : personename,
										"sexid" : sexid,
										"nationid" : nationid,
										"marriageid" : marriageid,
										"postid" : postid,
										"identityno" : identityno,
										"homeaddr" : homeaddr,
										"nowaddr" : nowaddr,
										"birthdate" : birthdate,
										"graduatedate" : graduatedate,
										"officedate" : officedate,
										"memberdate" : memberdate,
										"ismembered" : ismembered,
										"contractdate" : contractdate,
										"iscontracted" : iscontracted,
										"leavedate" : leavedate,
										"school" : school,
										"major" : major,
										"englishdegreeid" : englishdegreeid,
										"bankCardNo":bankCardNo,
										"providentFund":bankCardNo,
										"insuranceno" : insuranceno,
										"bankinsuranceno" : bankinsuranceno,
										"companycardno" : companycardno,
										"hkmcpassport" : hkmcpassport,
										"iceperson" : iceperson,
										"icetel" : icetel,
										"email" : email,
										"mobile" : mobile,
										"weixin" : weixin,
										"qq" : qq,
										"remark" : remark,
										"createtime" : createtime,
										"updatetime" : updatetime,
										"active" : active

									},
									async : false,//同步
									success : function(data) {
										if (data.status == 200) {
											parent.Public.tips({
												content : "修改员工信息成功"
											})
											CallBack({
												"AddEditDel":"addEditDel"
											});
										} else {
											parent.Public.tips({
												type : 1,
												content : "修改员工信息失败:"
														+ data.msg
											})
										}
									}
								});
							}
						}
					}, {
						id : "cancel",
						name : btnname[1]
					})
		}

		//生成树
		Public.zTree = {
			init : function($target, opts, setting, callback) {
				var tree = {
					zTree : {},
					opts : {
						showRoot : true,
						defaultClass : '',
						disExpandAll : false,//showRoot为true时无效
						callback : '',
						rootTxt : '全部'
					},
					setting : {
						edit : {
							enable : false
						},
						check : {
							enable : false
						},
						view : {
							dblClickExpand : false,
							showLine : true,
							selectedMulti : false
						},
						data : {
							simpleData : {
								enable : true,
								idKey : "Id",
								pIdKey : "ParentId",
								rootPId : ""
							}
						},
						callback : {
						//beforeClick: function(treeId, treeNode) {}
						}
					},
					_getTemplate : function(opts) {
						this.id = 'tree' + parseInt(Math.random() * 10000);
						var _defaultClass = "ztree";
						if (opts) {
							if (opts.defaultClass) {
								_defaultClass += ' ' + opts.defaultClass;
							}
						}
						return '<ul id="'+this.id+'" class="' + _defaultClass + '"></ul>';
					},
					getData : function(opts) {
						var self = this;
						self.opts = $.extend(true, self.opts, opts);
						var opts = self.opts;
						var selectedValue = opts.queryString;
						if (selectedValue == undefined
								|| selectedValue == 'undefined'
								|| selectedValue == 'null'
								|| selectedValue == null) {
							selectedValue = "";
						}
						selectedValue = encodeURI(encodeURI(selectedValue));//防止中文乱码
						$
								.ajax({
									url : 'employee/selectTreeNode_department.do?companyId='
											+ companyId
											+ '&companyid='
											+ companyId,
									type : 'GET',
									dataType : 'json',
									async : false,//同步执行，防止出现执行不成功的问题
									success : function(data) {
										data = data.data.items;
										for ( var e in data) {
											for ( var k in data[e]) {
												if (k == 'DeptName') {
													data[e]['name'] = data[e][k];
												}
											}
										}
										self.render(data);
									}
								})
					},
					render : function(data) {
						var self = this;
						var callback = self.opts.afterRender;
						if (self.opts.showRoot) {
							data.unshift({
								name : self.opts.rootTxt,
								id : 0
							});
							self.obj.addClass('showRoot');
						}
						if (!data.length)
							return;
						self.zTree = $.fn.zTree.init(self.obj, self.setting,
								data);
						self.zTree.expandAll(!self.opts.disExpandAll);
						if (callback && typeof callback === 'function') {
							callback(self, data);
						}
					},
					init : function($target, opts, setting, callback) {
						if ($target.length === 0) {
							return;
						}
						var self = this;
						self.opts = $.extend(true, self.opts, opts);
						self.container = $($target);
						self.obj = $(self._getTemplate(opts));
						self.container.append(self.obj);
						setting = $.extend(true, self.setting, setting);

						self.getData();
						var callback = self.opts.inited;
						if (callback && typeof callback === 'function') {
							callback(self);
						}
						return self;
					}
				}
				return tree.init($target, opts, setting, callback)
			}
		}
		Public.categoryTree = function($obj, opts) {
			var _last;
			if ($obj.length === 0) {
				return;
			}
			opts = opts ? opts : opts = {};
			var opts = $.extend(true, {
				inputWidth : '145',
				width : '',//'auto' or int
				height : '240',//'auto' or int
				trigger : true,
				defaultClass : 'ztreeCombo',
				disExpandAll : false,//展开全部
				defaultSelectValue : 0,
				showRoot : false,//显示root选择
				rootTxt : '',
				queryString : '',
				treeSettings : {
					callback : {
						beforeClick : function(treeId, treeNode) {
							if (_Combo.obj) {
								console.log(treeNode)
								_Combo.obj.val(treeNode.name);
								_Combo.obj.data('id', treeNode.Id); //获取id值的地方
								_Combo.hideTree();
							}
						}
					}
				}
			}, opts);
			var readonly = opts.disable ? ' readonly' : '';
			var _Combo = {
				container : $('<span class="ui-tree-wrap" style="width:'+opts.inputWidth+'px"></span>'),
				obj : $('<input type="text" class="input-txt" style="width:'
						+ (opts.inputWidth - 16) + 'px" id="' + $obj.attr('id')
						+ '" autocomplete="off"  placeholder="全部"' + readonly
						+ ' value="' + ($obj.val() || $obj.text()) + '">'),
				trigger : $('<span class="trigger"></span>'),
				data : {},
				init : function() {
					var _parent = $obj.parent();
					var _this = _Combo;
					$obj.remove();
					_this.obj.appendTo(_this.container);
					if (opts.trigger) {
						_this.container.append(_this.trigger);
					}
					_this.container.appendTo(_parent);
					var len = $(".ztreeCombo").length;
					for (var i = 0; i < len; i++) {
						if (i == len) {
							$(".ztreeCombo").eq(i).show();
						} else {
						}
						;
					}
					;
					opts.afterRender = function(publicTree, data) {
						_this.zTree = publicTree;

						if (publicTree) {
							for (var i = 0, len = data.length; i < len; i++) {
								_this.data[data[i].id] = data[i];
							}
							;
							if (opts.defaultSelectValue !== '') {
								_this.selectByValue(opts.defaultSelectValue);
							}
							;
						}
					};
					opts.inited = function(publicTree) {
						_this.zTree = publicTree;
						if (publicTree) {
							publicTree.obj.css({
								'max-height' : opts.height
							});
							_this._eventInit();
							$(".ztreeCombo").css({
								"top" : "143px",
								"left" : "524px",
								"width" : "250px"
							});
							$(".inventory .ztreeCombo").css({
								"top" : "50px",
								"left" : "319px",
								"width" : "200px"
							});
						}
					}

					_this.zTree = Public.zTree.init($('body'), opts,
							opts.treeSettings);
					return _this;
				},
				showTree : function() {
					var _this = _Combo;
					if (!_this.zTree)
						return;
					if (_this.zTree) {
						var offset = _this.obj.offset();
						var topDiff = _this.obj.outerHeight();
						var w = opts.width ? opts.width : _this.obj.width();
						var _o = _this.zTree.obj.hide();
						_o.css({
							width : w,
							top : offset.top + topDiff,
							left : offset.left - 1
						});
					}
					var _o = _this.zTree.obj.show();
					_this.isShow = true;
					_this.container.addClass('ui-tree-active');
				},
				hideTree : function() {
					var _this = _Combo;
					if (!_this.zTree)
						return;
					var _o = _this.zTree.obj.hide();
					_this.isShow = false;
					_this.container.removeClass('ui-tree-active');
					if (opts.callback)
						opts.callback()
				},
				_eventInit : function() {
					var _this = this;
					if (opts.trigger) {
						_this.trigger.on('click', function(e) {
							e.stopPropagation();
							if (_this.zTree && !_this.isShow) {
								_this.showTree();
							} else {
								_this.hideTree();
							}
						});
					}
					;
					_this.obj.on('click', function(e) {
						e.stopPropagation();
						if (_this.zTree && !_this.isShow) {
							_this.showTree();
						} else {
							_this.hideTree();
						}
					});
					_this.obj.on('keyup', function(e) {
						e.stopPropagation();
						var self = $(this);
						_last = e.timeStamp;
						setTimeout(function() {
							if (_last - e.timeStamp == 0) {
								_this.zTree.getData({
									queryString : self.val()
								});
							}
						}, 1000)
					})
					if (_this.zTree) {
						_this.zTree.obj.on('click', function(e) {
							e.stopPropagation();
						});
					}

					$(document).click(function() {
						_this.selectByText($(_this.obj).val())
						_this.hideTree();
					});

				},
				getValue : function() {
					/* debugger */
					var id = this.obj.data('id') || 0;
					return id;
				},
				getText : function() {
					if (this.obj.data('id'))
						return this.obj.val();
					return '';
				},
				selectByValue : function(value) {
					if (value !== '') {
						if (this.data) {
							for (_temp in this.data) {
								var _temp = this.data[_temp];
								if (_temp.DeptCode === value) {
									this.obj.val(_temp.name)
									return this;
								}
							}
							;
							this.obj.val('');
						}
					}
					return this;
				},
				addData : function(parentNode, data) {
					this.zTree.zTree.addNodes(parentNode, {
						name : data.name,
						id : data.id
					});
					this.data[data.id] = data
				},
				selectByText : function(value) {

					var searchField = $("#searchField").val();
					var searchOper = $("#searchOper").val();
					var searchString = $("#searchString").val();
					var data = {
						searchField : searchField,
						searchOper : searchOper,
						searchString : searchString
					};
					CallBack(data);

					return this;
				}
			};
			return _Combo.init();
		}

		var param = {
			width : 150,
			inputWidth : 200,
			showRoot : true,
			rootTxt : parentname
		//默认显示
		};
		var categoryTree = Public.categoryTree($("#parentname"), {
			inputWidth : 160,
			height : 200,
			width : 150,
			rootTxt : "请选择类别"
		});
		function storedeptname() {
			var a = $("#deptname").val();
			return a;
		}
		function storedeptcode() {
			var b = $("#deptid").val();
			return b;
		}
		function storedpartentcode() {
			var c = $("#parentId").val();
			return c;
		}
	</script>
</body>
</html>